import request from '@/utils/request'

// 查询活动列表
export function listProductActivity(query) {
  return request({
    url: '/api/activity/getAllActivities',
    method: 'get',
    params: query
  })
}

// 查询活动详细
export function getProductActivity(activityId) {
  return request({
    url: '/api/activity/' + activityId,
    method: 'get'
  })
}

// 新增活动
export function addProductActivity(data) {
  return request({
    url: '/api/activity/create',
    method: 'post',
    data: data
  })
}

// 修改活动
export function updateProductActivity(data) {
  return request({
    url: '/api/activity/update',
    method: 'put',
    data: data
  })
}

// 删除活动
export function delProductActivity(activityId) {
  return request({
    url: '/api/activity/delete/' + activityId,
    method: 'delete'
  })
}

// 上传活动海报
export function uploadActivityPoster(activityId, file) {
  const data = new FormData();
  data.append('file', file);
  return request({
    url: `/api/activity/${activityId}/upload-poster`,
    method: 'post',
    data: data
  })
}

//为活动添加商品
export function addActivityProduct(activityId, params) {
  return request({
    url: `/api/activity/${activityId}/sku`,
    method: "post",
    params: params
  })
}

//从活动中移除商品
export function deleteActivityProduct(activityId, skuId){
  return request({
    url: `/api/activity/${activityId}/sku/${skuId}`,
    method: "delete"
  })
}

//更新活动商品价格接口
export function updateActivityProductPrice(activityId, skuId, price){
  return request({
    url: `/api/activity/${activityId}/sku/${skuId}/price`,
    method: "put",
    params: { price }
  })
}

//获取活动下的所有商品
export function getActivityProductList(activityId){
  return request({
    url: `/api/activity/${activityId}/sku`,
    method: "get"
  })
}
